#!/usr/bin/python
# -*- coding: utf-8 -*-
# @Project    : AutomatedTesting
# @Name       : log_record.py
# @IDE        : PyCharm
# @Author     : OneYoung
# @Created    : 2025/8/24 21:02
# @Desc       : 日志简单配置, 参考 https://github.com/Delgan/loguru

import os
from loguru import logger
from application.settings import LOG_OUTPUT, BASE_DIR, LOG_CONFIG
from utils.get_time import str_date

# 移除控制台输出
if not LOG_OUTPUT:
    logger.remove(handler_id=None)

# 按当前时间命名日志存放文件夹,不存在时创建
log_path = os.path.join(BASE_DIR, 'logs', str_date())
if not os.path.exists(log_path):
    os.makedirs(log_path)

# 普通日志文件
info_file = os.path.join(log_path, f'info.log')
info = logger.add(info_file, level="INFO", **LOG_CONFIG)

# 错误日志文件
error_file = os.path.join(log_path, f'error.log')
error = logger.add(error_file, level="ERROR", **LOG_CONFIG)
